﻿using HML.Design;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace HML
{
    /// <summary>
    ///  该控件显示围绕一组具有可选标题的控件的框架
    /// </summary>
    [Description("该控件显示围绕一组具有可选标题的控件的框架")]
    [TypeConverter(typeof(PropertyOrderConverter))]
    [Designer(typeof(GroupPanelPlusDesigner))]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(GroupPanelPlus), "Controls.GroupPanelPlus.Resources.GroupPanelPlus.bmp")]
    public class GroupPanelPlus : DpiContainerControl, ISkinObject
    {
        #region 主题

        private SkinObjectXmlMetadata skinObjectXmlMetadata = null;
        /// <summary>
        /// 主题对象在主题文件信息
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SkinObjectXmlMetadata SkinObjectXmlMetadata
        {
            get
            {
                if (this.skinObjectXmlMetadata == null)
                    this.skinObjectXmlMetadata = new SkinObjectXmlMetadata(Assembly.GetAssembly(typeof(GroupPanelPlus)).GetName().Name, typeof(GroupPanelPlus).Name);

                return this.skinObjectXmlMetadata;
            }
        }

        private SkinController skinController = null;
        /// <summary>
        /// 主题控制器
        /// </summary>
        [Description("主题控制器")]
        [Category("杂项")]
        [PropertyOrder(-360)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinController SkinController
        {
            get { return this.skinController; }
            set
            {
                if (this.skinController == value)
                    return;

                if (this.skinController != null)
                    this.skinController.RemoveSkinObject(this);

                this.skinController = value;

                if (this.skinController != null)
                    this.skinController.AddSkinObject(this);
            }
        }

        private SkinEnabledState skinEnabled= SkinEnabledState.Auto;
        /// <summary>
        /// 主题是否启用
        /// </summary>
        [Description("主题是否启用")]
        [Category("杂项")]
        [PropertyOrder(-300)]
        [DefaultValue(SkinEnabledState.Auto)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinEnabledState SkinEnabled
        {
            get { return this.skinEnabled; }
            set
            {
                if (this.skinEnabled == value)
                    return;

                this.skinEnabled = value;
                this.OnSkinChanged();
            }
        }

        private SkinStyle skinStyle = SkinStyle.Normal;
        /// <summary>
        /// 主题风格
        /// </summary>
        [Description("主题风格")]
        [Category("杂项")]
        [PropertyOrder(-260)]
        [DefaultValue(SkinStyle.Normal)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinStyle SkinStyle
        {
            get { return this.skinStyle; }
            set
            {
                if (this.skinStyle == value)
                    return;

                this.skinStyle = value;
                this.OnSkinChanged();
            }
        }

        private StyleAppearanceObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [Category("杂项")]
        [PropertyOrder(-200)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleAppearanceObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleAppearanceObject(this, null);
                return this.stateAppearance;
            }
        }

        /// <summary>
        /// 主题已更改
        /// </summary>
        public virtual void OnSkinChanged()
        {
            SkinManager.SyncSkinValueToProperty(this);
            this.NCInvalidate();
            this.Invalidate();
        }

        private ISkinObject followSkinObject = null;
        /// <summary>
        /// 主题设置跟随指定主题对象（自己的设置不再生效，提供给代码使用）
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual ISkinObject FollowSkinObject
        {
            get { return this.followSkinObject; }
            set
            {
                if (this.followSkinObject == value)
                    return;

                this.followSkinObject = value;
                this.OnSkinChanged();
            }
        }

        public virtual bool GetSkinObjectSkinStateCore()
        {
            return SkinManager.GetSkinObjectSkinState(this.FollowSkinObject ?? this);
        }

        protected override void OnParentBackColorChanged(EventArgs e)
        {
            base.OnParentBackColorChanged(e);

            this.NCInvalidate();
            this.Invalidate();
        }

        protected override void OnParentForeColorChanged(EventArgs e)
        {
            base.OnParentForeColorChanged(e);

            this.NCInvalidate();
            this.Invalidate();
        }

        void ISkinObject.InitializeInvalidate()
        {
            throw new NotImplementedException();
        }

        void ISkinObject.Invalidate()
        {
            this.NCInvalidate();
        }

        #endregion

        #region 停用事件

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler RightToLeftChanged
        {
            add { base.RightToLeftChanged += value; }
            remove { base.RightToLeftChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ImeModeChanged
        {
            add { base.ImeModeChanged += value; }
            remove { base.ImeModeChanged -= value; }
        }

        #endregion

        #region 新增属性

        private int borderThickness = 1;
        /// <summary>
        /// 边框厚度
        /// </summary>
        [Description("边框厚度")]
        [Category("杂项")]
        [PropertyOrder(-198)]
        [DefaultValue(1)]
        public int BorderThickness
        {
            get { return this.borderThickness; }
            set
            {
                if (this.borderThickness == value || value < 0)
                    return;

                this.borderThickness = value;
                this.Send_WM_NCCALCSIZE_Message();
            }
        }

        private GroupPanelPlusTitleAlignments titleAlignment = GroupPanelPlusTitleAlignments.Left;
        /// <summary>
        /// 标题栏对齐方式
        /// </summary>
        [Description("标题栏对齐方式")]
        [Category("杂项")]
        [PropertyOrder(-196)]
        [DefaultValue(GroupPanelPlusTitleAlignments.Left)]
        public GroupPanelPlusTitleAlignments TitleAlignment
        {
            get { return this.titleAlignment; }
            set
            {
                if (this.titleAlignment == value)
                    return;

                this.titleAlignment = value;
                this.Send_WM_NCPAINT_Message();
            }
        }

        private TBMargin titleTBMargin = new TBMargin(8, 8);
        /// <summary>
        /// 标题栏文本上下外边距
        /// </summary>
        [Description("标题栏文本上下外边距")]
        [Category("杂项")]
        [PropertyOrder(-194)]
        [DefaultValue(typeof(TBMargin), "8,8")]
        public TBMargin TitleTBMargin
        {
            get { return this.titleTBMargin; }
            set
            {
                if (value.Top < 0)
                    value.Top = 0;
                if (value.Bottom < 0)
                    value.Bottom = 0;
                if (this.titleTBMargin == value)
                    return;

                this.titleTBMargin = value;
                this.Send_WM_NCCALCSIZE_Message();
            }
        }

        private IconObject icon;
        /// <summary>
        /// 图标
        /// </summary>
        [Description("图标")]
        [PropertyOrder(-192)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public IconObject Icon
        {
            get
            {
                if (this.icon == null)
                    this.icon = new IconObject(this);
                return this.icon;
            }
        }


        #endregion

        #region 重写属性

        protected override Size DefaultSize
        {
            get { return new Size(200, 100); }
        }

        public override string Text
        {
            get { return base.Text; }
            set
            {
                if (base.Text == value)
                    return;

                base.Text = value;
                this.Send_WM_NCPAINT_Message();
            }
        }

        public override Font Font
        {
            get { return base.Font; }
            set
            {
                if (base.Font == value)
                    return;

                base.Font = value;
                this.Send_WM_NCPAINT_Message();
            }
        }

        #endregion

        #region 停用属性

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new bool AutoScroll
        {
            get { return base.AutoScroll; }
            set { base.AutoScroll = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Size AutoScrollMargin
        {
            get { return base.AutoScrollMargin; }
            set { base.AutoScrollMargin = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Size AutoScrollMinSize
        {
            get { return base.AutoScrollMinSize; }
            set { base.AutoScrollMinSize = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Point AutoScrollPosition
        {
            get { return base.AutoScrollPosition; }
            set { base.AutoScrollPosition = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft
        {
            get { return base.RightToLeft; }
            set { base.RightToLeft = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color BackColor
        {
            get { return this.StyleAppearance.BackColor; }
            set { }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color ForeColor
        {
            get { return this.StyleAppearance.TextColor; }
            set { }
        }

        #endregion

        #region 扩展

        private const int WM_NCCALCSIZE = 0x0083;// 当某个窗口的客户区域必须被核算时发送此消息   
        private const int WM_NCPAINT = 0x85;// 程序发送此消息给某个窗口当它（窗口）的框架必须被绘制时   
        private const int WM_NCACTIVATE = 0x86;// 此消息发送给某个窗口仅当它的非客户区需要被改变来显示是激活还是非激活状态 

        public struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }

        public struct NCCALCSIZE_PARAMS
        {
            /// <summary>
            /// 在移动或改变大小后的新坐标
            /// </summary>
            public RECT ncNewRectangle;
            /// <summary>
            /// 在移动或改变大小前的坐标
            /// </summary>
            public RECT ncOldRectangle;
            /// <summary>
            /// 移动或改变大小前的客户区坐标
            /// </summary>
            public RECT ncOldClientRectangle;
            public IntPtr lppos;
        }


        private const int SWP_NOSIZE = 0x0001;//保留当前大小 (忽略 cx 和 cy 参数) 。
        private const int SWP_NOMOVE = 0x0002; //保留当前位置(忽略 X 和 Y 参数) 。
        private const int SWP_NOZORDER = 0x0004;//保留当前 Z 顺序 (忽略 hWndInsertAfter 参数) 。
        private const int SWP_FRAMECHANGED = 0x0020;//将 WM_NCCALCSIZE 消息发送到窗口，即使窗口的大小未更改也是如此

        #endregion

        public GroupPanelPlus()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            this.Send_WM_NCCALCSIZE_Message();
            this.OnSkinChanged();

        }

        #region 重写

        protected override void OnScaleDpiChangedInitialize()
        {
            this.NCInvalidate();
            this.Invalidate();
        }

        protected override void OnEnabledChanged(EventArgs e)
        {
            base.OnEnabledChanged(e);

            this.NCInvalidate();
        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            int scale_borderThickness = this.BorderThickness == 1 ? 1 : (int)Math.Ceiling(this.BorderThickness * this.ScaleDpi);
            TBMargin scale_titleTBMargin = new TBMargin((int)Math.Ceiling(this.TitleTBMargin.Top * this.ScaleDpi), (int)Math.Ceiling(this.TitleTBMargin.Bottom * this.ScaleDpi));
            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
            int scale_titleHeight = scale_titleTBMargin.Top + font_metrics.GetFontRealHeight() + scale_titleTBMargin.Bottom;

            base.SetBoundsCore(x, y, Math.Max(width, scale_borderThickness * 2), Math.Max(height, scale_titleHeight + scale_borderThickness), specified);
        }

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_NCCALCSIZE:
                    {
                        NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
                        int scale_borderThickness = this.BorderThickness == 1 ? 1 : (int)Math.Ceiling(this.BorderThickness * this.ScaleDpi);
                        TBMargin scale_titleTBMargin = new TBMargin((int)Math.Ceiling(this.TitleTBMargin.Top * this.ScaleDpi), (int)Math.Ceiling(this.TitleTBMargin.Bottom * this.ScaleDpi));
                        int scale_titleHeight = scale_titleTBMargin.Top + font_metrics.GetFontRealHeight() + scale_titleTBMargin.Bottom;

                        RECT ncsize = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
                        ncsize.Top += scale_titleHeight;
                        ncsize.Left += scale_borderThickness;
                        ncsize.Right -= scale_borderThickness;
                        ncsize.Bottom -= scale_borderThickness;
                        Marshal.StructureToPtr(ncsize, m.LParam, false);

                        this.Send_WM_NCPAINT_Message();
                        return;
                    }
                case WM_NCPAINT:
                case WM_NCACTIVATE:
                    {
                        this.NCInvalidate();
                        return;
                    }
            }
            base.WndProc(ref m);
        }



        #endregion

        #region 虚方法

        /// <summary>
        /// 绘制非工作区域
        /// </summary>
        protected virtual void OnNCPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
            int scale_borderThickness = this.BorderThickness == 1 ? 1 : (int)Math.Ceiling(this.BorderThickness * this.ScaleDpi);
            TBMargin scale_titleTBMargin = new TBMargin((int)Math.Ceiling(this.TitleTBMargin.Top * this.ScaleDpi), (int)Math.Ceiling(this.TitleTBMargin.Bottom * this.ScaleDpi));
            int scale_titleHeight = scale_titleTBMargin.Top + font_metrics.GetFontRealHeight() + scale_titleTBMargin.Bottom;

            // 边框背景色
            SolidBrush title_back_sb = new SolidBrush(this.StyleAppearance.TitleBackColor);
            RectangleF title_rect = new RectangleF(g.VisibleClipBounds.X, g.VisibleClipBounds.Y, g.VisibleClipBounds.Width, scale_titleHeight);
            RectangleF left_rect = new RectangleF(0, scale_titleHeight, scale_borderThickness, g.VisibleClipBounds.Height - scale_titleHeight - scale_borderThickness);
            RectangleF right_rect = new RectangleF(g.VisibleClipBounds.Right - scale_borderThickness, scale_titleHeight, scale_borderThickness, g.VisibleClipBounds.Height - scale_titleHeight - scale_borderThickness);
            RectangleF bottom_rect = new RectangleF(0, g.VisibleClipBounds.Bottom - scale_borderThickness, g.VisibleClipBounds.Width, scale_borderThickness);
            g.FillRectangles(title_back_sb, new RectangleF[] { title_rect, bottom_rect, left_rect, right_rect });
            title_back_sb.Dispose();

            //标题图标
            if (this.Icon.Visible && this.Icon.Image != null)
            {
                int image_w = (int)Math.Ceiling(this.Icon.Size.Width * this.ScaleDpi);
                int image_h = (int)Math.Ceiling(this.Icon.Size.Height * this.ScaleDpi);

                Image image = this.Icon.Image;
                bool image_tmp = false;
                if (!this.Enabled)
                {
                    image = ControlHelper.CreateDisabledImage(this.Icon.Image);
                    image_tmp = true;
                }
                g.DrawImage(image, new RectangleF(g.VisibleClipBounds.X + scale_borderThickness + font_metrics.GetFontStereotypesMargim() * 2, g.VisibleClipBounds.Y + titleTBMargin.Top + font_metrics.GetFontRealHeight() / 2 - image_h / 2, image_w, image_h));

                if (image_tmp)
                {
                    image.Dispose();
                }
            }


            // 标题文本
            if (!String.IsNullOrWhiteSpace(Text))
            {
                SolidBrush title_text_sb = new SolidBrush(this.StyleAppearance.TitleTextColor);
                Size text_size = new Size((int)Math.Ceiling(g.MeasureString(this.Text, this.Font, int.MaxValue, StringFormat.GenericTypographic).Width), font_metrics.GetFontRealHeight());
                RectangleF text_rect = RectangleF.Empty;
                if (this.TitleAlignment == GroupPanelPlusTitleAlignments.Left)
                {
                    float text_x = g.VisibleClipBounds.X + scale_borderThickness + ((this.Icon.Visible && this.Icon.Image != null) ? font_metrics.GetFontStereotypesMargim() * 2 + (int)Math.Ceiling(this.Icon.Size.Width * this.ScaleDpi) + font_metrics.GetFontStereotypesMargim() * 2 : font_metrics.GetFontStereotypesMargim() * 2);
                    text_rect = new RectangleF(text_x, g.VisibleClipBounds.Y + titleTBMargin.Top, text_size.Width, text_size.Height);
                }
                else if (this.TitleAlignment == GroupPanelPlusTitleAlignments.Center)
                {
                    text_rect = new RectangleF(g.VisibleClipBounds.X + (g.VisibleClipBounds.Width - text_size.Width) / 2f, g.VisibleClipBounds.Y + titleTBMargin.Top, text_size.Width, text_size.Height);
                }
                else
                {
                    text_rect = new RectangleF(g.VisibleClipBounds.Right - text_size.Width - scale_borderThickness - font_metrics.GetFontStereotypesMargim() * 2, g.VisibleClipBounds.Y + titleTBMargin.Top, text_size.Width, text_size.Height);
                }

                g.DrawString(this.Text, this.Font, title_text_sb, text_rect.X, text_rect.Y, StringFormat.GenericTypographic);
                title_text_sb.Dispose();
            }


        }

        #endregion

        #region 私有方法

        /// <summary>
        /// 重新绘制非工作区
        /// </summary>
        private void NCInvalidate()
        {
            IntPtr hDC = IntPtr.Zero;
            Graphics g = null;
            ControlHelper.GetWindowGraphics(this.Handle, out g, out hDC);

            this.OnNCPaint(new PaintEventArgs(g, new Rectangle(0, 0, this.Width, this.Height)));
            g.Dispose();
            NativeMethods.ReleaseDC(this.Handle, hDC);
        }

        /// <summary>
        /// 发送非工作区绘制信息
        /// </summary>
        private void Send_WM_NCPAINT_Message()
        {
            NativeMethods.SendMessage(this.Handle, WM_NCPAINT, (IntPtr)1, (IntPtr)0);
        }

        /// <summary>
        /// 发送要求重新计算非工作区和绘制信息
        /// </summary>
        private void Send_WM_NCCALCSIZE_Message()
        {
            NativeMethods.SetWindowPos(this.Handle, (IntPtr)0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
        }

        #endregion

        #region 类

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class IconObject
        {
            private GroupPanelPlus owner = null;
            internal IconObject(GroupPanelPlus owner) { this.owner = owner; }

            #region 属性

            private bool visible = false;
            /// <summary>
            /// 是否显示图标
            /// </summary>
            [Description("是否显示图标")]
            [PropertyOrder(-194)]
            [DefaultValue(false)]
            public bool Visible
            {
                get { return this.visible; }
                set
                {
                    if (this.visible == value)
                        return;

                    this.visible = value;
                    this.owner.Send_WM_NCPAINT_Message();
                }
            }

            private Size size = new Size(14, 14);
            /// <summary>
            /// 标题栏图标大小
            /// </summary>
            [Description("标题栏图标大小")]
            [PropertyOrder(-192)]
            [DefaultValue(typeof(Size), "14,14")]
            public Size Size
            {
                get { return this.size; }
                set
                {
                    if (this.size == value || value.Width < 0 || value.Height < 0)
                        return;

                    this.size = value;
                    this.owner.NCInvalidate();
                }
            }

            private Image image = null;
            /// <summary>
            /// 标题栏图标
            /// </summary>
            [Description("标题栏图标")]
            [PropertyOrder(-180)]
            [DefaultValue(null)]
            public Image Image
            {
                get { return this.image; }
                set
                {
                    if (this.image == value)
                        return;

                    this.image = value;
                    this.owner.Send_WM_NCPAINT_Message();
                }
            }

            #endregion

        }

        #endregion

        #region 外观

        public class StyleAppearanceObject : AppearanceObjectBase
        {
            internal StyleAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

            #region 属性

            private Color skinBackColor = Color.Empty;
            private readonly Color defaultBackColor = SystemColors.Control;
            private Color backColor = Color.Empty;
            /// <summary>
            /// 背景颜色
            /// </summary>
            [Description("背景颜色")]
            [PropertyOrder(-198)]
            [SkinProperty(true, true)]
            public Color BackColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinBackColor != Color.Empty)
                    {
                        return this.skinBackColor;
                    }

                    if (this.backColor != Color.Empty)
                    {
                        return this.backColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.BackColor;
                    }

                    return this.defaultBackColor;
                }
                set
                {
                    if (this.backColor == value)
                        return;

                    this.backColor = value;
                    ((GroupPanelPlus)this.owner).Send_WM_NCPAINT_Message();
                }
            }
            private bool ShouldSerializeBackColor()
            {
                return this.backColor != Color.Empty;
            }
            private void ResetBackColor()
            {
                this.backColor = Color.Empty;
                ((GroupPanelPlus)this.owner).Send_WM_NCPAINT_Message();
            }

            private Color skinTextColor = Color.Empty;
            private readonly Color defaultTextColor = SystemColors.ControlText;
            private Color textColor = Color.Empty;
            /// <summary>
            /// 文本颜色
            /// </summary>
            [Description("文本颜色")]
            [PropertyOrder(-197)]
            [SkinProperty(true, true)]
            public Color TextColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinTextColor != Color.Empty)
                    {
                        return this.skinTextColor;
                    }

                    if (this.textColor != Color.Empty)
                    {
                        return this.textColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.ForeColor;
                    }

                    return this.defaultTextColor;
                }
                set
                {
                    if (this.textColor == value)
                        return;

                    this.textColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeTextColor()
            {
                return this.textColor != Color.Empty;
            }
            private void ResetTextColor()
            {
                this.textColor = Color.Empty;
                this.Invalidate();
            }

            private Color skinTitleBackColor = Color.Empty;
            private readonly Color defaultTitleBackColor = SystemColors.GradientActiveCaption;
            private Color titleBackColor = Color.Empty;
            /// <summary>
            /// 标题栏背景颜色
            /// </summary>
            [Description("标题栏背景颜色")]
            [PropertyOrder(-196)]
            [SkinProperty(true, false)]
            public Color TitleBackColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore())
                    {
                        return this.skinTitleBackColor;
                    }

                    if (this.titleBackColor != Color.Empty)
                    {
                        return this.titleBackColor;
                    }

                    return this.defaultTitleBackColor;
                }
                set
                {
                    if (this.titleBackColor == value)
                        return;

                    this.titleBackColor = value;
                    ((GroupPanelPlus)this.owner).Send_WM_NCPAINT_Message();
                }
            }
            private bool ShouldSerializeTitleBackColor()
            {
                return this.titleBackColor != Color.Empty;
            }
            private void ResetTitleBackColor()
            {
                this.titleBackColor = Color.Empty;
                ((GroupPanelPlus)this.owner).Send_WM_NCPAINT_Message();
            }

            private Color skinTitleTextColor = Color.Empty;
            private readonly Color defaultTitleTextColor = SystemColors.Window;
            private Color titleTextColor = Color.Empty;
            /// <summary>
            /// 标题栏文本颜色
            /// </summary>
            [Description("标题栏文本颜色")]
            [PropertyOrder(-195)]
            [SkinProperty(true, false)]
            public Color TitleTextColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore())
                    {
                        return this.skinTitleTextColor;
                    }

                    if (this.titleTextColor != Color.Empty)
                    {
                        return this.titleTextColor;
                    }

                    return this.defaultTitleTextColor;
                }
                set
                {
                    if (this.titleTextColor == value)
                        return;

                    this.titleTextColor = value;
                    ((GroupPanelPlus)this.owner).Send_WM_NCPAINT_Message();
                }
            }
            private bool ShouldSerializeTitleTextColor()
            {
                return this.titleTextColor != Color.Empty;
            }
            private void ResetTitleTextColor()
            {
                this.titleTextColor = Color.Empty;
                this.Invalidate();
            }

            #endregion

        }

        #endregion

    }
}
